package com.zuikaku.nettydemo.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class MyNettyServerHandler extends SimpleChannelInboundHandler<String> {
    private int count =0;

    protected void channelRead0(ChannelHandlerContext channelHandlerContext, String s) throws Exception {
        count++;
        System.out.printf("收到来自客户端消息："+s+" 第："+count+"次");
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush("你好，我是netty服务器");
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("客户端离线了");
    }
}
